﻿#region XNA Libraries

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

#endregion

#region SDK Libraries

using main.sdk.audio;
using main.sdk.display;
using main.sdk.display.object2d;
using main.sdk.input;
using main.sdk.scene;

#endregion

namespace main.src.scene
{

    public sealed class Scene_Intro : Scene_Base
    {

        private readonly Texture2D[] Textures = {
                                                    Program.Self.Content.Load<Texture2D>("rsc/picture/Global Game Jam"),
                                                    Program.Self.Content.Load<Texture2D>("rsc/picture/Seven Game")
                                                };

        private const byte ALPHA_GAIN = 5;
        private const byte ALPHA_LOSS = 5;
        private const byte TIME_WAIT  = 60;

        private readonly Sprite Sprite   = new Sprite();
        private byte            Index    = 0;
        private byte            Step     = 0;
        private byte            Timer;

        public override void Start()
        {
            if (Textures.Length == 0)
            {
                Scene.Set(new Scene_Title());
                return;
            }
            Sprite.Texture = Textures[0];
            Sprite.Alpha = 0;
            Sprite.Center();
        }

        public override void Update()
        {
            switch (Step)
            {
                case 0:
                    Sprite.Alpha += ALPHA_GAIN;
                    if (Sprite.Alpha == 255)
                    {
                        Timer = TIME_WAIT;
                        Step  = 1;
                    }
                    break;
                case 1:
                    --Timer;
                    if (Timer == 0)
                        Step = 2;
                    break;
                case 2:
                    Sprite.Alpha -= ALPHA_LOSS;
                    if (Sprite.Alpha == 0)
                    {
                        ++Index;
                        if (Index >= Textures.Length)
                            Scene.Set(new Scene_Title());
                        else
                        {
                            Sprite.Texture = Textures[Index];
                            Sprite.Center();
                            Step = 0;
                        }
                    }
                    break;
            }
        }

        public override void Terminate()
        {
            Sprite.Dispose();
        }

    }

}